//
//  YQJSBridge.h
//  CusWebView
//
//  Created by yeqiang on 2024/2/19.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@import WebKit;

typedef void (^YQJSResponseCallBack)(NSString *callBackId, NSDictionary *response);
typedef void (^YQJSHandler)(id data);

@interface YQJSBridge : NSObject <WKScriptMessageHandler, WKNavigationDelegate>

// js 桥接执行结束的回调
@property (nonatomic, copy) YQJSResponseCallBack jsCallBack;
@property (nonatomic, weak) WKWebView *webView;

// 初始化
+ (instancetype)bridgeForWebView:(WKWebView *)webView;
- (void)setupInstance:(WKWebView *)webView;

- (void)registerHandler:(NSString *)handlerName handler:(YQJSHandler)handler;

- (void)setWebViewDelegate:(id<WKNavigationDelegate>)webViewDelegate;
// 初始化拦截方法
- (void)initStub;
// 销毁拦截方法
- (void)deallocStub;

@end

NS_ASSUME_NONNULL_END
